package com.xy.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    private static final String TOPIC_EXCHANGE = "testTopicExchange";

    private static final String TOPIC_QUEUE = "testTopicQueue";

    private static final String TOPIC_FIRST_QUEUE = "testTopicFirstQueue";

    private static final String TOPIC_SECOND_QUEUE = "testTopicSecondQueue";

    @Bean
    public Exchange testTopicExchange() {
        return ExchangeBuilder.topicExchange(TOPIC_EXCHANGE).build();
    }

    @Bean
    public Queue testTopicQueue() {
        return QueueBuilder.durable(TOPIC_QUEUE).build();
    }

    @Bean
    public Queue testTopicFirstQueue() {
        return QueueBuilder.durable(TOPIC_FIRST_QUEUE).build();
    }

    @Bean
    public Queue testTopicSecondQueue() {
        return QueueBuilder.durable(TOPIC_SECOND_QUEUE).build();
    }

    @Bean
    public Binding topicBinding(@Qualifier("testTopicExchange") Exchange exchange, @Qualifier("testTopicQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("item.#").noargs();
    }

    @Bean
    public Binding topicFirstBinding(@Qualifier("testTopicExchange") Exchange exchange, @Qualifier("testTopicFirstQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("item.first").noargs();
    }

    @Bean
    public Binding topicSecondBinding(@Qualifier("testTopicExchange") Exchange exchange, @Qualifier("testTopicSecondQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("item.second").noargs();
    }

}
